package cn.fintecher.pangolin.service.dataimp.model.request;

import cn.fintecher.pangolin.entity.mysql.QCaseInfo;
import com.querydsl.core.BooleanBuilder;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * @Auther: xiaqun
 * @Description: 分案导出请求参数
 * @Date: 17:27 2019/10/19
 */

@Data
public class ExportDistributeRequest {
    @ApiModelProperty(value = "委托方ID")
    private String principalId;

    @ApiModelProperty(value = "批次号")
    private String batchNumber;

    @ApiModelProperty(value = "机构code")
    private String departCode;

    @ApiModelProperty(value = "委案城市")
    private String cities;

    public BooleanBuilder getBuilder() {
        BooleanBuilder builder = new BooleanBuilder();
        QCaseInfo qCaseInfo = QCaseInfo.caseInfo;
        builder.and(qCaseInfo.department.isNull());
        builder.and(qCaseInfo.currentCollector.isNotNull());
        if (StringUtils.isNotBlank(this.principalId)) {
            builder.and(qCaseInfo.principalId.eq(this.principalId));
        }
        if (StringUtils.isNotBlank(this.batchNumber)) {
            builder.and(qCaseInfo.batchNumber.eq(this.batchNumber));
        }
        if (StringUtils.isNotBlank(this.departCode)) {
            builder.and(qCaseInfo.currentCollector.department.departCode.like(this.departCode + "%"));
        }
        if (StringUtils.isNotBlank(this.cities)) {
            List<String> city = Arrays.asList(this.cities.split(","));
            city.forEach(e -> {
                if (e.equals("")) {
                    city.remove(e);
                }
            });
            builder.and(qCaseInfo.city.in(city));
        }
        return builder;
    }
}
